package com.xzt.security.controller;

import com.xzt.security.dto.*;
import com.xzt.security.mapper.UserMapper;
import com.xzt.security.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {

    @Autowired
    private  UserService userService;

    @PostMapping("/register")
    public RegisterResponse register(@RequestBody RegisterRequest request) {
        return userService.register(request);
    }

    @PostMapping("/login")
    public LoginResponse login(@RequestBody LoginRequest request) {
        return userService.login(request);
    }

    @GetMapping("/index")
    public UserInfoResponse getCurrentUserInfo(){
        return userService.getCurrentUserInfo();
    }

    @GetMapping("/admin/index")
    public UserInfoResponse getAdminUserInfo(){
        return userService.getAdminUserInfo();
    }
}